package com.es.pay.grade.server;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;
import java.util.HashMap;

import com.es.util.db.Dao;

public class StorefrontGradeImport {

	public boolean importStorefrontGradeExcelList(
			ArrayList<ArrayList> queryParms) throws Exception {
		Dao dao = new Dao();
		try {
			String sql = "insert into storefront_grade(scode,sname,sells_code,sells_name,sells_type,s_area,s_province,s_city,s_city_rank,s_type,s_rank,s_oversee,s_oversee_id,wk1,wk2,wk3,wk4,wk5,m_number,m_average,s_data,brand,record_name) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
			dao.updateBatch(sql, queryParms);
		} catch (Exception e) {
			System.out.print(e.getMessage());
			return false;
		} finally {
			dao.close();
		}
		return true;
	}

	public ArrayList<HashMap<String, Object>> importStorefrontGradeExcelListDo(
			String sessionId, String intime) throws Exception {
		Dao dao = new Dao();
		ArrayList<HashMap<String, Object>> map = new ArrayList<HashMap<String, Object>>();
		ArrayList<String> query = new ArrayList<String>();
		query.add(sessionId);
		query.add(intime);
		try {
			String sql = ("{call STOREFRONT_GRADE(?,?)}");
			ResultSet resultSet = dao.executePro(sql, query);
			ResultSetMetaData rss = resultSet.getMetaData();

			while (resultSet.next()) {
				if (rss.getColumnCount() == 1) {
					HashMap<String, Object> rowNum = new HashMap<String, Object>();
					rowNum.put("rowNum", (String) resultSet.getObject(rss
							.getColumnName(1)));
					map.add(rowNum);
					return map;
				}
				HashMap<String, Object> errorlist = new HashMap<String, Object>();
				// shop_code,shop_name,shop_index,error
				for (int i = 0; i < rss.getColumnCount(); i++) {
					errorlist.put(rss.getColumnName(i + 1), (String) resultSet
							.getObject(rss.getColumnName(i + 1)));
				}
				map.add(errorlist);
			}
		} catch (Exception e) {
			System.out.print(e.getMessage());
		} finally {
			dao.close();
		}
		return map;
	}

}